package net.shopxx.action.member;


import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.jsp.PageContext;

import net.shopxx.entity.ProductComment;
import net.shopxx.service.ProductCommentService;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.oscache.base.Cache;
import com.opensymphony.oscache.web.ServletCacheAdministrator;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

/**
 * 后台Action类 - 商品评论
 */

@ParentPackage("member")
public class ProductcommentAction extends BaseMemberAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8982038175671094442L;


	private ProductComment productComment;
	private String pid;
	@Resource
	private ProductCommentService productCommentService;



	// 列表
	public String list() {
		pager = productCommentService.getMemberOwnCommentPager(getLoginMember(), pager);
		return LIST;
	}
	// 添加
	public String add() {
		return INPUT;
	}

	// 编辑
	public String edit() {
		productComment = productCommentService.load(id); 
		return INPUT;
	}
	
	
	
	// 更新
	
	@InputConfig(resultName = "error")
	public String update() throws Exception {
		ProductComment persistent = productCommentService.load(id); 
		persistent.setStatus(productComment.getStatus());
		productCommentService.update(persistent);
		flushCache();
		redirectionUrl = "productcomment!list.action?pid="+persistent.getProduct().getId();
		return SUCCESS;
	}
	

	// 删除
	public String delete() throws Exception {
		productCommentService.delete(ids);
		flushCache();
		return ajaxJsonSuccessMessage("删除成功！");
	}
	
	
	public ProductComment getProductComment() {
		return productComment;
	}
	public void setProductComment(ProductComment productComment) {
		this.productComment = productComment;
	}
	
	
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}
	// 更新页面缓存
	private void flushCache() {
		Cache cache = ServletCacheAdministrator.getInstance(getRequest().getSession().getServletContext()).getCache(getRequest(), PageContext.APPLICATION_SCOPE); 
		cache.flushAll(new Date());
	}
	

}